package com.javainterface.dao;

import com.javainterface.utils.Md5;
import org.jdom.Document;
import org.springframework.stereotype.Repository;


/**
 * 调用万户接口
 * 继承获取GetToken
 */

@Repository
public class GetList extends GetToken {
    Document doc = null;

    //任一用户账号，可以在OA中不存在
    String curUserAccount = "wanhu";
    //whconfig.xml中serviceKeyList节点下面的name="serviceKey"的值，任一组即可
    String serviceKey = "webappKey";
    //whconfig.xml中serviceKeyList节点下面的name="fixedStr"的值，任一组即可
    String fixedStr = "webapp";

//    String serviceURL = "http://10.0.12.171:7001/defaultroot/xfservices/GeneralWeb",
    String serviceURL = "http://10.0.12.181:8070/defaultroot/xfservices/GeneralWeb",
            serviceTNS = "http://com.whir.service/GeneralWeb", method = "OAManager";

    // 取待办已办我的待阅已阅等文件列表
    public String getDealList(String userId, String userAccount, String workStatus) {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>workflow_searchDealWithList</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
//                "<userId>12864</userId>" +
                "<userId>" + userId + "</userId>" +
//                "<userAccount>behcsys</userAccount>" +
                "<userAccount>" + userAccount + "</userAccount>" +
                "<title></title>" +
                "<pageOffset>1</pageOffset>" +
                "<pageSize>100</pageSize>" +
//                "<workStatus>102</workStatus>" +
                "<workStatus>" + workStatus + "</workStatus>" +
                "<processId></processId>" +
                "<emergence></emergence>" +
                "<pressDeal></pressDeal>" +
                "<searchStatus></searchStatus>" +
                "<orderType></orderType>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
//        System.out.println(sendXml);
        System.out.println(backXml);
        return backXml;
    }

    // 获取信息头条列表，带图片信息列表
    public String getPortalInfoList() {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>getPortalInfoList</cmd>" +
                "<domain>0</domain>" +
                "<ServiceToken>" + getServiceToken() + "</ServiceToken>" +
//                "<serviceKey>"+this.serviceKey+"</serviceKey>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
                "<userId>12864</userId>" +
//                "<userAccount>behcsys</userAccount>" +
                "<orgId>1</orgId>" +
                "<orgIdString>1</orgIdString>" +
                "<title></title>" +
                "<channelType></channelType>" +
                "<userDefine></userDefine>" +
                "<searchChannelId></searchChannelId>" +
                "<page_offset>0</page_offset>" +
                "<pageSize>100</pageSize>" +
                "<ezmobileType></ezmobileType>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
        return backXml;
    }

    // 取信息列表
    public String information_getMobileList() {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>information_getMobileList</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
                "<userId>12864</userId>" +
                "<userAccount>behcsys</userAccount>" +
                "<orgId>1</orgId>" +
                "<orgIdString></orgIdString>" +
                "<type>all</type>" +
                "<userDefine></userDefine>" +
                "<informationId></informationId>" +
                "<userChannelName>信息管理</userChannelName>" +
                "<search></search>" +
                "<channelType>0</channelType>" +
                "<depart></depart>" +
                "<searchDate></searchDate>" +
                "<searchBeginDate></searchBeginDate>" +
                "<searchEndDate></searchEndDate>" +
                "<searchIssuerName></searchIssuerName>" +
                "<title></title>" +
                "<informationKey></informationKey>" +
                "<subtitle></subtitle>" +
                "<append></append>" +
                "<searchChannel></searchChannel>" +
                "<pager_offset>100</pager_offset>" +
                "<pageSize>10</pageSize>" +
                "<userChannelId>1</userChannelId>" +
                "<mobilePortal></mobilePortal>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
        return backXml;
    }

    // 收件箱信息列表
    public String getMailReceiveBoxList(String userId, String userAccount, String beginDate, String endDate) {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>getMailReceiveBoxList</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
                "<subject></subject>" +
//                "<userId>12864</userId>" +
                "<userId>" + userId + "</userId>" +
//                "<userAccount>behcsys</userAccount>" +
                "<userAccount>" + userAccount + "</userAccount>" +
                "<curpage>1</curpage>" +
                "<pagesize>100</pagesize>" +
//                "<beginDate>2021-01-01</beginDate>" +
                "<beginDate>" + beginDate + "</beginDate>" +
//                "<endDate>2021-12-31</endDate>" +
                "<endDate>" + endDate + "</endDate>" +
                "<postername></postername>" +
                "<readFlag>0</readFlag>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
        System.out.println("邮件："+sendXml);
        return backXml;
    }

    //获取用户信息列表
    public String getUserList() {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>getUserList</cmd>" +
                "<domain>0</domain>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
        return backXml;
    }

    //获取新闻列表栏目
    public String getAllInfoChannels() {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>getAllInfoChannels</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
                "<pager_offset>1</pager_offset>" +
                "<pageSize>10</pageSize>" +
                "<channelName></channelName>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
        System.out.println(sendXml);
        System.out.println(backXml);
        return backXml;
    }

    //获取新闻列表
    public String getInformationList(String userId, String orgId, String status) {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String userChannelName = "";
        if (status.equals("通知公告")) {
            userChannelName = "通知公告";
        } else {
            userChannelName = "信息交流";
        }
        String channelId="6695";
        if(!status.equals("通知公告"))
            channelId="20966";
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>getInformationList</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
//                "<userId>12864</userId>"+
//                "<orgId>139448</orgId>"+
                "<userId>" + userId + "</userId>" +
                "<orgId>" + orgId + "</orgId>" +
                "<orgIdString></orgIdString>" +
                "<type>all</type>" +
                "<userChannelName>" + userChannelName + "</userChannelName>" +
                "<channelType>0</channelType>" +
                "<pager_offset>100</pager_offset>" +
//                "<channelId>"+channelId+"</channelId>" +
                "<channelId></channelId>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
//        System.out.println("文件交换："+sendXml);
//        System.out.println(backXml);
        return backXml;
    }

    //获取会议通知
    public String getMeetingNoticeList(String userId, String orgId) {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>meetingNoticeList</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
//                "<userId>12864</userId>"+
//                "<orgId>139448</orgId>"+
                "<userId>" + userId + "</userId>" +
                "<orgId>" + orgId + "</orgId>" +
                "<meetingMotif></meetingMotif>" +
                "<handleType>0</handleType>" +
                "<pageSize>100</pageSize>" +
                "<currentPage>1</currentPage>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
//        System.out.println(sendXml);
//        System.out.println(backXml);
        return backXml;
    }

    public String getUserInfoByUserAccounts(String accounts) {
        Long time = System.currentTimeMillis();
        String s = this.serviceKey + "0" + this.curUserAccount + "0" + time + this.fixedStr;
        String sendXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<input>" +
                "<key>" + Md5.getMD5Str("DKezOFFICE12.3") + "</key>" +
                "<cmd>getUserInfoByUserAccounts</cmd>" +
                "<domain>0</domain>" +
                "<serviceToken>" + getServiceToken() + "</serviceToken>" +
                "<serviceKey>evoserviceKey</serviceKey>" +
                "<userKey>sys</userKey>" +
                "<userKeyType>0</userKeyType>" +
                // 以上都是必须的参数
                "<accounts>" + accounts + "</accounts>" +
                "</input>";
        String backXml = start(sendXml, serviceURL, serviceTNS, method);
        if (backXml.length() > 0) {
            ParseDoc(backXml);
        }
//        System.out.println(sendXml);
//        System.out.println(backXml);
        return backXml;
    }
}

